from django.contrib import admin
from .settings import MEDIA_ROOT
from django.urls import path, include, re_path
from django.views.static import serve
from rest_framework.documentation import include_docs_urls
from django.conf.urls import url
from django.views.generic import TemplateView
import xadmin

from user_operation.views import UserFavViewSte,LeavingMessageViewSte,UserAddressViewSet
from users.views import SmsCodeViewSet, UserRegViewSet
from rest_framework.routers import DefaultRouter
from goods.views import GoosdListViewSet, GoodsCategoryViewSet, HotSearchsViewset,BannerCarouselViewSet,NewGoodsViewSet
from trade.views import ShoppingCartViewSet,OrderViewset,AliPayView

# 绑定url
router = DefaultRouter()
# 搜索接口
router.register(r'goods', GoosdListViewSet, base_name='goods')
#商品获取接口
router.register(r'categorys', GoodsCategoryViewSet, base_name='categorys')
#热搜接口
router.register(r'hotsearchs', HotSearchsViewset, base_name="hotsearchs")
#获取手机验证码
router.register(r'code', SmsCodeViewSet, base_name='code')
#用户
router.register(r'users', UserRegViewSet, base_name='users')
#收藏接口
router.register(r'userfavs', UserFavViewSte, base_name='userfavs')
#留言接口
router.register(r'messages', LeavingMessageViewSte, base_name='messages')
#收获地址
router.register(r'address', UserAddressViewSet, base_name='address')
#购物车接口
router.register(r'shopcarts', ShoppingCartViewSet, base_name='shopcarts')
#订单
router.register(r'orders', OrderViewset, base_name='orders')
#首页轮播图
router.register(r'banners', BannerCarouselViewSet, base_name='banners')
#首页轮播图
router.register(r'newgoods', NewGoodsViewSet, base_name='newgoods')






from rest_framework_jwt.views import obtain_jwt_token


urlpatterns = [
    path('admin/', xadmin.site.urls),
    # 富文本
    path('ueditor/', include('DjangoUeditor.urls')),
    # 文件路径
    re_path('media/(?P<path>.*)', serve, {"document_root": MEDIA_ROOT}),  # 配置url去media下面取数据
    # 绑定routerd的url
    url(r'^', include(router.urls)),
    # 自动化文档, 1.11版本中注意此处前往不要加$符号
    path('docs/', include_docs_urls(title='API文档')),
    # 调试登录
    path(r'api-auth/', include('rest_framework.urls')),
    path(r'alipay/return', AliPayView.as_view(),name='alipay_'),
    # jwt的token认证
    url(r'^login/', obtain_jwt_token),
    #主页
    path('index', TemplateView.as_view(template_name='index.html'),name='index'),# 主页启动路径

]
